<?php

require_once('../../config/maptrick.conf.php');
require_once(SITE_ROOT . 'lib/PHT.php');
require_once(SITE_ROOT . 'class/bean/League.class.php');
require_once(SITE_ROOT . 'class/db/DBLeague.class.php');

try {
	if ($_GET["pass"] != SCRIPT_PWD) die("Incorrect password");
	
	$HT = new CHPPConnection(CONSUMERKEY, CONSUMERSECRET);
	$HT->setOauthToken(USERTOKEN);
	$HT->setOauthTokenSecret(USERTOKENSECRET);
	
	$dbleague = new DBLeague();
	$leagues = $dbleague->getLeaguesByLevel(1);
	
	foreach ($leagues as $league) {
		$league->setName($HT->getLeague($league->getLeagueID())->getLeagueLevelName());
	}
	$dbleague->saveLeagues($leagues);
}
catch (Exception $e) {
	echo $e->getMessage();
}

?>